package logic

import (
	"context"
	"fmt"
	"wx/models/mysql"

	"wx/wxrpc/internal/svc"
	"wx/wxrpc/wxrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *wxrpc.ListRequest) (*wxrpc.ListResponse, error) {
	// todo: add your logic here and delete this line
	var wx mysql.WeiXin
	mysql.DB.Where("id =?", in.Id).Find(&wx)
	if wx.ID == 0 {
		return nil, fmt.Errorf("商品不存在")
	}

	return &wxrpc.ListResponse{
		Id:      int64(wx.ID),
		Context: wx.Context,
		Image:   wx.Image,
		UserId:  int64(wx.UserId),
		Mobile:  wx.Mobile,
	}, nil
}
